<?php

/*
  Project     : 48c6c450f1a4a0cc53d9585dc0fee742
  Created on  : Mar 16, 2013, 11:29:15 PM
  Author      : Truong Khuong - khuongxuantruong@gmail.com
  Description :
  Purpose of the stylesheet follows.
 */

class category_model extends CI_Model {

    function __construct($type = null, $init = false) {
        parent::__construct();
        $this->cate_type = $type;
        $this->HieCats = array();
        if ($init)
            $this->HierarchicalCats(0);
    }
    function get_cat_by_alias_parent($cate_alias='',$parent=null){
        if($parent)$this->db->where("cate_parent", $parent);
        $query = $this->db
                ->where("cate_alias", $cate_alias)
                ->get("categories");
        return $query->row();
    }
    function get_cat_by_alias_type($cate_alias='',$type=null){
        if($type)$this->db->where("cate_type", $type);
        $query = $this->db
                ->where("cate_alias", $cate_alias)
                ->get("categories");
        return $query->row();
    }
    function get_cat_by_id_parent($cate_id='',$parent=null){
        if($parent)$this->db->where("cate_parent", $parent);
        $query = $this->db
                ->where("cate_id", $cate_id)
                ->get("categories");
        return $query->row();
    }
    function get($cate_id='',$parent=null) {
        if($parent)$this->db->where("cate_parent", $parent);
        $query = $this->db
                ->where("cate_id", $cate_id)
//                ->or_where("cate_alias", $cate_id)
                ->get("categories");
        return $query->row();
    }
    function get_by_type($type = null) {
        if ($type != null)
            $this->db->where('cate_type', $type);
        $query = $this->db
                ->order_by('cate_parent', 'ASC')
                ->order_by('cate_position', 'ASC')
                ->order_by('cate_insert', 'DESC')
                ->get("categories");
        return $query->result();
    }
    function get_in_types($types = null) {
        if ($types != null){
            if(!is_array($types))$types=array($types);
            $this->db->where_in('cate_type', $types);
        }
        $query = $this->db
                ->order_by('cate_parent', 'ASC')
                ->order_by('cate_position', 'ASC')
                ->order_by('cate_insert', 'DESC')
                ->get("categories");
        return $query->result();
    }
    function get_by_parent($parent = null) {
        if ($parent != null)
            $this->db->where('cate_parent', $parent);
        $query = $this->db
                ->order_by('cate_position', 'ASC')
                ->order_by('cate_insert', 'DESC')
                ->get("categories");
        return $query->result();
    }
    

}

?>
